package com.qfedu.yanglao20admin.article.controller;


import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20.common.annotation.LogInfo;
import com.qfedu.yanglao20.entity.article.Article;
import com.qfedu.yanglao20admin.article.service.ArticleTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "文章类型")
@RestController
@RequestMapping("/articleType")
public class ArticleTypeController {


    @Resource
    private ArticleTypeService articleTypeService;

    @LogInfo
    @ApiOperation(value = "展示文章类型", notes = "展示文章类型")
    @GetMapping("/list")
    public CommonResult selectAllType() {
        List<Article> articles = articleTypeService.ListArticleType();
        return CommonResult.success(articles);
    }

    @LogInfo
    @ApiOperation(value = "根据id删除文章类型", notes = "根据id删除文章类型")
    @GetMapping("/delete")
    public CommonResult deleteArticleType(@RequestParam @ApiParam("文章类型id") Integer id) {
        articleTypeService.deleteById(id);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "添加文章类型", notes = "添加文章类型")
    @PostMapping("/add")
    public CommonResult<Article> addArticleType(Article article) {
        articleTypeService.addArticleType(article);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "根据id查询文章类型", notes = "根据id查询文章类型")
    @GetMapping("/query")
    public CommonResult queryArticleType(@RequestParam @ApiParam("文章类型id") Integer id) {
        Article article = articleTypeService.queryArticleType(id);
        return CommonResult.success(article);
    }

    @LogInfo
    @ApiOperation(value = "修改文章类型", notes = "修改文章类型")
    @PostMapping("/update")
    public CommonResult<Article> updateArticleType(Article article) {
        articleTypeService.updateArticleType(article);
        return CommonResult.success();
    }

    @LogInfo
    @ApiOperation(value = "添加文章类型下级", notes = "添加文章类型下级")
    @PostMapping("/addType")
    public CommonResult addArticleUpType(Article article) {
        articleTypeService.addIdByName(article);
        return CommonResult.success();
    }

}
